package com.ys.erp.stage_user_service.controller;

import com.ys.erp.framework.annotation.CheckEmpLogin;
import com.ys.erp.framework.annotation.RedissonLock;
import com.ys.erp.framework.annotation.ResponseResult;
import com.ys.erp.framework.annotation.StageLoginEmp;
import com.ys.erp.framework.bean.dto.StageEmpDTO;
import com.ys.erp.framework.response.PageDTO;
import com.ys.erp.stage_user_service.bean.condition.UserMoneyCondition;
import com.ys.erp.stage_user_service.bean.vo.CatMoneyOrderTotalVO;
import com.ys.erp.stage_user_service.bean.vo.InMoneySettingVO;
import com.ys.erp.stage_user_service.bean.vo.PageInCatMoneyRecordVO;
import com.ys.erp.stage_user_service.service.UserMoneyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author minamiyama
 * @date 2024/10/30 14:04
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/manage/user/money")
@Tag(name = "后台用户金额相关接口", description = "后台用户金额相关接口")
@ResponseResult
public class UserMoneyController {

    private final UserMoneyService userMoneyService;

    @PostMapping("/pageInRecord")
    @Operation(summary = "充值幺币记录", description = "充值幺币记录")
    @CheckEmpLogin
    public PageDTO<PageInCatMoneyRecordVO> pageInRecord(@RequestBody @Valid UserMoneyCondition.PageInCatMoneyRecordCon con,
                                                        @StageLoginEmp StageEmpDTO empDto) {
        return userMoneyService.pageInRecord(empDto, con);
    }

    @PostMapping("/catMoneyOrderTotal")
    @Operation(summary = "微信充值幺币总金额次数", description = "微信充值幺币总金额次数")
    @CheckEmpLogin
    public CatMoneyOrderTotalVO catMoneyOrderTotal(@RequestBody @Valid UserMoneyCondition.PageInCatMoneyRecordCon con,
                                                   @StageLoginEmp StageEmpDTO empDto) {
        return userMoneyService.catMoneyOrderTotal(empDto, con);
    }

    @PostMapping("/inMoneySettingList")
    @Operation(summary = "充值幺币配置集", description = "充值幺币配置集")
    @CheckEmpLogin
    public List<InMoneySettingVO> inMoneySettingList(@StageLoginEmp StageEmpDTO empDto) {
        return userMoneyService.inMoneySettingList(empDto);
    }

    @PostMapping("/addOrUpdateInMoneySetting")
    @Operation(summary = "新增或更新幺币配置", description = "新增或更新幺币配置")
    @CheckEmpLogin
    @RedissonLock(key = "#empDto.id")
    public void addOrUpdateInMoneySetting(@RequestBody @Valid UserMoneyCondition.AddOrUpDateInMoneySettingCon con,
                            @StageLoginEmp StageEmpDTO empDto) {
        userMoneyService.addOrUpdateInMoneySetting(empDto, con);
    }

}
